from re import A
import jwt


class Myjwt():
    def __init__(self):
        self.SECRET_KEY='uy67i867tu56ru5/*5ry56435453'

    # 生成token
    def jwt_encode(self,data):
        token = jwt.encode(data,self.SECRET_KEY,algorithm='HS256')
        return token
    
    def jwt_decode(self,token):
        try:
            data = jwt.decode(token,self.SECRET_KEY,algorithms='HS256')
            newtoken = jwt.encode(data,self.SECRET_KEY,algorithm='HS256')
            return newtoken
        except:
            return None
    
    def check(self,token,newtoken):
        if token==newtoken:
            return True
        return False
    

myjwt = Myjwt()

token = myjwt.jwt_encode({'data':{'name':'sdf'}})
print(token)
newtoken = myjwt.jwt_decode('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7Im5hbWUiOiJzZGYifX0.wbU-j5qynvCQfhJig8N593N_bEytKhF8XQTNo04pDWc')

flag = myjwt.check(token,newtoken)
print(flag)